﻿using Fluent.HtmlModel;
using Fluent.Logging;
using Fluent.Verifying;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Fluent
{
    public abstract class WebPageBase
    {
        private const BindingFlags NonPublicAndFlattenedBindingOptions = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
        private const string QueryParamFormat = "{0}={1}";

        public Browser Browser { get; private set; }
        public Dictionary<string, object> URLPatternValues { get; protected set; }
        public abstract string URLPattern { get; }

        public WebPageBase(Browser browser)
        {
            this.Browser = browser;
        }

        public void Navigate()
        {
            throw new NotImplementedException();
        }

        protected string GetRunningURL()
        {
            throw new NotImplementedException();
        }

    }

    public abstract class WebPageBase<TPage> : WebPageBase
        where TPage : WebPageBase
    {
        public WebPageBase(Browser browser)
            : base(browser) { }

        public new TPage Navigate()
        {
            base.Navigate();

            return this as TPage;
        }

        public TVerifyPoint ToVerify<TVerifyPoint>()
            where TVerifyPoint : IVerifyPoint
        {
            Type verifyPointType = typeof(TVerifyPoint);
            ConstructorInfo constructor = verifyPointType.GetConstructor(new[] { typeof(TPage) });
            return (TVerifyPoint)constructor.Invoke(new[] { this as TPage });
        }
    }
}
